﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Catering_Rules;
using System.Text;
using System.Data;

namespace Catering.Catering_Page.AjaxHandler
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class WebServiceSanshFenxi : System.Web.Services.WebService
    {

        [WebMethod]
        public YingyangsuFenxi GetYingyangsuFenxiBZ(string AreaID, string ClassID, string StrDTime)
        {
            int Year = Convert.ToInt32(StrDTime);
            DataViewForReport dvfr = new DataViewForReport();
            StringBuilder result = new StringBuilder("");
            DataTable dt = dvfr.GetNutrientCompositionGroupByMonth(AreaID, ClassID, Year);
            YingyangsuFenxi yysfx = new YingyangsuFenxi();
            yysfx.YYSFXs = new YingyangsuFenxiModel[10];
            yysfx.YYSFXs[0] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[1] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[2] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[3] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[4] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[5] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[6] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[7] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[8] = new YingyangsuFenxiModel();
            yysfx.YYSFXs[9] = new YingyangsuFenxiModel();

            yysfx.YYSFXs[0].name = "能量";
            yysfx.YYSFXs[1].name = "蛋白质";
            yysfx.YYSFXs[2].name = "脂肪";
            yysfx.YYSFXs[3].name = "碳水化合物";
            yysfx.YYSFXs[4].name = "膳食纤维";
            yysfx.YYSFXs[5].name = "维生素A";
            yysfx.YYSFXs[6].name = "维生素B1";
            yysfx.YYSFXs[7].name = "维生素B2";
            yysfx.YYSFXs[8].name = "维生素C";
            yysfx.YYSFXs[9].name = "维生素E";
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    decimal content = Convert.ToDecimal(dt.Rows[i]["content"]);//标准消耗量
                    int nutritionElementsID = Convert.ToInt32(dt.Rows[i]["NutritionElementsID"]);//营养元素名称ID
                    string elements = dt.Rows[i]["Elements"].ToString();//营养元素名称
                    int month = Convert.ToInt32(dt.Rows[i]["Month"]);//月份
                    if (nutritionElementsID < 11)
                    {
                        if (yysfx.YYSFXs[nutritionElementsID - 1].data == null)
                        {
                            yysfx.YYSFXs[nutritionElementsID - 1].data = new decimal[12];
                        }
                        yysfx.YYSFXs[nutritionElementsID - 1].data[month - 1] = content;
                    }

                }
                dt.Dispose();
            }
            return yysfx;
        }
    }

    public class YingyangsuFenxi
    {
        private YingyangsuFenxiModel[] yysfxs;

        public YingyangsuFenxiModel[] YYSFXs
        {
            get { return yysfxs; }
            set { yysfxs = value; }
        }
    }

    public class YingyangsuFenxiModel
    {
        private string m_Name;

        public string name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }
        private decimal[] m_Data;

        public decimal[] data
        {
            get { return m_Data; }
            set { m_Data = value; }
        }
    }
}
